/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-06-04 14:48:41
 * @LastEditors: voanit
 * @LastEditTime: 2022-06-05 09:17:37
 */
import { hasToken } from '@/utils/storage'
import { Route, Redirect } from 'react-router-dom'
console.log(hasToken(), 45)
// children就是要展示的组件
export const PrivateRoute = ({ children, ...rest }: any) => {
  return (
    <Route
      {...rest}
      render={props => {
        if (hasToken()) {
          return children
        }
        return (
          <Redirect
            to={{
              pathname: '/login',
              state: {
                from: props.location.pathname // 回跳地址
              }
            }}
          />
        )
      }}
    />
  )
}
